import os

import pandas as pd
import re


def find_log_id_data(log_id, file_name='flask.log'):
    # 读取文本文件
    script_path = os.path.abspath('./logs/' + file_name)
    with open(script_path, 'r') as f:
        text_data = f.readlines()
    text_lines = [line.strip() for line in text_data]

    # 将文本数据转换为 Pandas 数据框
    text_df = pd.DataFrame(text_lines, columns=['text'])

    # 构造正则表达式模式
    pattern = re.compile(r'{}'.format(log_id))
    # 提取包含关键词的文本行
    text_df['match'] = text_df['text'].apply(lambda x: True if re.search(pattern, x) else False)
    matched_text_df = text_df[text_df['match']]
    matched_text_lines = list(matched_text_df['text'])

    return matched_text_lines
